<?php
/**
 * Model_Settings 设置模型
 *
 * @package Movoin Blog
 * @subpackage Model
 *
 */

//{{include
FLEA::loadClass('Controller_Base');
//}}

class Model_Settings extends Controller_Base
{

    /**
     * tblSettings
     *
     * @var mixed
     * @access public
     */
    var $tblSettings;

    /**
     * Model_Settings
     *
     * @access public
     * @return void
     */
    function Model_Settings()
    {
        $this->tblSettings = & FLEA::getSingleton('Table_Settings');
    }

    /**
     * getSettings
     *
     * @access public
     * @return void
     */
    function getSettings()
    {
        $data = $this->tblSettings->find(1);
        $options = unserialize($data['options']);
        unset($data['options']);
        return array_merge($data,$options);

    }

    /**
     * update
     *
     * @param mixed $data
     * @access public
     * @return void
     */
    function update(&$data)
    {
        $row = $this->_prepareData($this->tblSettings->meta);
        unset($row['options']);
        foreach($data as $k=>$d) {
            if ($row[$k]) {
                unset($data[$k]);
            }
        }
        $row['options'] = serialize($data);
        if ($this->tblSettings->save($row)) {
            return 'succeed!';
        } else {
            return 'failed!';
        }
    }

}
